﻿var TransferCustomer = {};

TransferCustomer.inte = function () {
    EmployeePrompt.getDepartAndEmployeeByInput('', 'hidTransferDepartmentName', 'txtTransferEmployeeName', 'hidUserId', $('#hasPublicAccount').attr('exceptme'), "private", '1', null, null, true, true, false);
    agencyVerify.NeedSmartTips("", "#txtTransferEmployeeName", "#hidUserId", "业务员必需从智能提示中选择", true);
    $('#divTransferCustomerTab label').click(function () {
        if ($(this).find("input").val() == '转给他人') {
            $('#spanTransferPrivateCustomer').show();
            $('#spanTransferpublicCustomer').hide();
        } else if ($(this).find("input").val() == '转为公客') {
            $('#spanTransferPrivateCustomer').hide();
            $('#spanTransferpublicCustomer').show();

        }
    });
    $("#divTransferCustomerTab label").eq(0).click();
};

TransferCustomer.transfer = function (isPublic) {
    var reqData = {};
    if (isPublic) {
        if ($('#selPublicDepartment').val() == '-1') {
            //激活change事件
            $(".aui_content #selPublicDepartment").change();
            return false;
        }
        var customerIds = TransferCustomer.getCustomerIds();
        if (customerIds == false) {
            return false;
        }
        reqData = { 'CustomerIds': customerIds.join(','), 'userId': $('#selPublicDepartment').val(),'IsPublicCustomerClick':false };
    } else {
        //验证
        var customerIds = TransferCustomer.getCustomerIds();
        if (customerIds == false) {
            return false;
        }
        if ($('#hidUserId').val() == "") {
            //激活change事件
            $(".aui_content input[isnull=1]").change();
            return false;
        }
       
        reqData = { 'departmentid': $('#hidTransferDepartmentName').val(), 'CustomerIds': customerIds.join(','), 'userId': $('#hidUserId').val(), 'IsPublicCustomerClick': $("#hidIsPublicCustomerClick").val() };
    }
    $.AjaxAgency('/Customer/inquiry-transfer-ajax',reqData , function (data) {
        if (data == 'ok') {
            //成功
            if (TransferCustomer.successed) {
                TransferCustomer.successed();
            }
        } else {
            $.OKDialogAgency('<div class="tc">' + data + '</div>');
        }
    });
};


